﻿namespace WMS6.Web
{
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Web;
    using WMS6.Web.VASServiceRef;

    public class VASServiceClientProxy : BasePage
    {
        public string DeleteOperationInfo(List<string> operationInfoIDs)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            using (VASServicesClient client = new VASServicesClient("WSHttpBinding_IVASServices"))
            {
                return client.DeleteOperationInfo(operationInfoIDs, pubParasInfo);
            }
        }

        public string DeleteWorkCenterInfo(List<string> workCenterIDs)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            using (VASServicesClient client = new VASServicesClient("WSHttpBinding_IVASServices"))
            {
                return client.DeleteWorkCenterInfo(workCenterIDs, pubParasInfo);
            }
        }

        public DataSet GetAllOperation()
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            using (VASServicesClient client = new VASServicesClient("WSHttpBinding_IVASServices"))
            {
                return client.GetAllOperation(pubParasInfo);
            }
        }

        public DataSet GetAllWorkCenter()
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            using (VASServicesClient client = new VASServicesClient("WSHttpBinding_IVASServices"))
            {
                return client.GetAllWorkCenter(pubParasInfo);
            }
        }

        public static VASServiceClientProxy GetInstance()
        {
            return new VASServiceClientProxy();
        }

        public DataSet GetOperationByQueryEntity(OperationQueryEntity operationQuery)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            using (VASServicesClient client = new VASServicesClient("WSHttpBinding_IVASServices"))
            {
                return client.GetOperationByQueryEntity(operationQuery, pubParasInfo);
            }
        }

        public OperationInfo GetOperationInfoByID(string operationInfoID)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            using (VASServicesClient client = new VASServicesClient("WSHttpBinding_IVASServices"))
            {
                return client.GetOperationInfoByID(operationInfoID, pubParasInfo);
            }
        }

        public DataSet GetWorkCenterByQueryEntity(WorkCenterQueryEntity workCenterQuery)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            using (VASServicesClient client = new VASServicesClient("WSHttpBinding_IVASServices"))
            {
                return client.GetWorkCenterByQueryEntity(workCenterQuery, pubParasInfo);
            }
        }

        public WorkCenterInfo GetWorkCenterInfoByID(string workCenterID)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            using (VASServicesClient client = new VASServicesClient("WSHttpBinding_IVASServices"))
            {
                return client.GetWorkCenterInfoByID(workCenterID, pubParasInfo);
            }
        }

        private PubParasInfo InitPubParasInfo()
        {
            if (base.UserInfo != null)
            {
                return new PubParasInfo { UserID = base.UserInfo.UserID, UserLanguage = base.UserInfo.Preference.Lang, CurrentWH = base.UserInfo.CurrentWH };
            }
            HttpContext.Current.Response.Redirect("../Login.aspx?from=Logout", true);
            return null;
        }

        public string InsertOperationInfo(OperationInfo operationInfo)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            using (VASServicesClient client = new VASServicesClient("WSHttpBinding_IVASServices"))
            {
                return client.InsertOperationInfo(operationInfo, pubParasInfo);
            }
        }

        public string InsertOperationInfo(WorkCenterInfo workCenterInfo)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            using (VASServicesClient client = new VASServicesClient("WSHttpBinding_IVASServices"))
            {
                return client.InsertWorkCenterInfo(workCenterInfo, pubParasInfo);
            }
        }

        public string UpdateOperationInfo(OperationInfo operationInfo)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            using (VASServicesClient client = new VASServicesClient("WSHttpBinding_IVASServices"))
            {
                return client.UpdateOperationInfo(operationInfo, pubParasInfo);
            }
        }

        public string UpdateOperationInfo(WorkCenterInfo workCenterInfo)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            using (VASServicesClient client = new VASServicesClient("WSHttpBinding_IVASServices"))
            {
                return client.UpdateWorkCenterInfo(workCenterInfo, pubParasInfo);
            }
        }
    }
}

